package com.wfl.sampling.web;
import com.wfl.sampling.dao.ActivityDao;
import com.wfl.sampling.entity.Activity;
import com.wfl.sampling.entity.formData;
import com.wfl.sampling.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
    public class FormController {
    @Autowired
    private ActivityService activityService;
    private ActivityDao activityDao;
    @PostMapping ("/order/orderHandle")
    public String  modifyActivity(@RequestParam("id") int id,@RequestParam("examine") int examine,@RequestParam("remark") String remark){
        List<Activity> ac = activityService.findActivityByActivityId(id); // Method to fetch activity by id

        Activity activity = ac.get(0);
        System.out.println("old:"+activity);
        // Update the activity details
        activity.setExamine(examine);
        activity.setRemark(remark);
        System.out.println(examine);
        System.out.println(id);
        System.out.println(remark);
        System.out.println(activity);
        // Save the updated activity back to the database
        boolean updateSuccess = activityService.modifyActivityById(activity); System.out.println();

        // Method to update activity
        if (updateSuccess) {
            // Redirect to a success page
            System.out.println(1);
            return "redirect:/admin/orderManage_0_0_0";
        } else {
            // Redirect to an error page or back to the form with error messages
            System.out.println(2);
            return null;
        }
    }

    }

